import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';

import {AppComponent} from './app.component';
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {Http, HttpModule, JsonpModule} from "@angular/http";
import {Router, RouterModule, Routes} from "@angular/router";
import {HomeComponent} from './home/home.component';
import {LoginComponent} from './login/login.component';
import {MyContentComponent} from './my-content/my-content.component';
import {HeaderComponent} from './header/header.component';
import {ExamListComponent} from './exam-list/exam-list.component';
import {UpdatePassComponent} from './update-pass/update-pass.component';
import {ReportErrorsComponent} from './report-errors/report-errors.component';
import {SysMsgsComponent} from './sys-msgs/sys-msgs.component';
import {MsgsComponent} from './msgs/msgs.component';
import {ReportComponent} from './report/report.component';
import {FooterComponent} from './footer/footer.component';
import {ReportErrorComponent} from './report-error/report-error.component';
import {SysMsgComponent} from './sys-msg/sys-msg.component';
import {LoginGuard} from "./guard/loginGuard";
import { EchartOptionDirective } from './report/base-data/echart-option.directive';
import {ChartsService} from "./report/charts.service";
import { WaveComponent } from './report/wave/wave.component';
import { BaseDataComponent } from './report/base-data/base-data.component';
import {BrowserAnimationsModule} from "@angular/platform-browser/animations";
import {LoginService} from "./login/login.service";
import {NgbModule, NgbPagination} from "@ng-bootstrap/ng-bootstrap";
import {ExamListService} from "./exam-list/exam-list.service";
import { ReportsFilterPipe } from './pipe/reports-filter.pipe';
import { TranslateModule, TranslateLoader, TranslateStaticLoader } from 'ng2-translate';

const routeConfig: Routes = [
  {path: '', redirectTo: '/rector', pathMatch: 'full'},
  {path: 'rector', component: MyContentComponent,  canActivate:[LoginGuard],
    children: [
    {path: '', component: HomeComponent},
    {path: 'updatePass', component: UpdatePassComponent},
    {path: 'reportErrors', component: ReportErrorsComponent},
    {path: 'sysMsgs', component: SysMsgsComponent},
    {path: 'sysMsgs/:id', component: MsgsComponent},
    {path: 'examList', component: ExamListComponent},
    {path: 'reports/:id', component: ReportComponent,
      children:[
        { path: '',redirectTo:'wave',pathMatch:'full'},
        { path: 'wave', component: WaveComponent },
        { path: 'baseData', component: BaseDataComponent },
        { path: '**', redirectTo:'wave' }
      ]}
      ]},
  {path: 'login', component: LoginComponent},
  {path: '**', redirectTo:'/rector'}
];

export function createTranslateLoader(http: Http) {
  return new TranslateStaticLoader(http, './assets/i18n', '.json');
}

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    LoginComponent,
    MyContentComponent,
    HeaderComponent,
    ExamListComponent,
    UpdatePassComponent,
    ReportErrorsComponent,
    SysMsgsComponent,
    MsgsComponent,
    ReportComponent,
    FooterComponent,
    ReportErrorComponent,
    SysMsgComponent,
    EchartOptionDirective,
    WaveComponent,
    BaseDataComponent,
    ReportsFilterPipe
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpModule,
    JsonpModule,
    ReactiveFormsModule,
    TranslateModule.forRoot({
      provide: TranslateLoader,
      useFactory: (createTranslateLoader),
      deps: [Http]
    }),
    NgbModule.forRoot(),
    RouterModule.forRoot(routeConfig)
  ],
  providers: [LoginGuard,ChartsService,LoginService,ExamListService],
  bootstrap: [AppComponent]
})
export class AppModule {
}
